package org.test.Disance;

import org.gavaghan.geodesy.Ellipsoid;
import org.gavaghan.geodesy.GeodeticCalculator;
import org.gavaghan.geodesy.GeodeticCurve;
import org.gavaghan.geodesy.GlobalCoordinates;
import org.test.Point;

/**
 * 使用 geodesy 类库
 */
public class ByGeodesy {
    static Point beijing = Point.parse("116.534119,39.923984", "北京");
    static Point guangzhou = Point.parse("113.29845,23.140121", "广州");
//    static Point beijing = Point.parse("116.505364,39.802991", "万源街");
//    static Point guangzhou = Point.parse("116.51326,39.793231", "荣京东街");

    public static void main(String[] args) {

        //创建GeodeticCalculator，调用计算方法，传入坐标系、经纬度用于计算距离
        GeodeticCurve geoCurve = new GeodeticCalculator().calculateGeodeticCurve(
                Ellipsoid.Sphere,
                new GlobalCoordinates(ByGeodesy.beijing.getLatitude(), beijing.getLongitude()),
                new GlobalCoordinates(guangzhou.getLatitude(), guangzhou.getLongitude())
        );

        System.out.println("距离: " + geoCurve.getEllipsoidalDistance());
        System.out.println("方位（度）:" + geoCurve.getAzimuth());
        System.out.println(geoCurve.getReverseAzimuth());
        // WGS84 4701.260219874908
        // Sphere 4715.085736444097


        // 创建大地测量计算器
        GeodeticCalculator calculator = new GeodeticCalculator();
        // 设置参考椭球体（这里使用WGS84椭球体，适用于大多数地理坐标计算）
        Ellipsoid ellipsoid = Ellipsoid.WGS84;

        //         //坐标1为北京，坐标2为广州
        //    double bearing = D.bearing(39.923984, 116.534119, 23.140121, 113.29845);

        // 将当前点和上一个点转换为GlobalCoordinates对象
        GlobalCoordinates thisCoords = new GlobalCoordinates(116.534119, 39.923984);
        GlobalCoordinates lastCoords = new GlobalCoordinates(113.29845, 23.140121);

        // 计算当前点到上一个点的距离和方位角
        GeodeticCurve curveToLast = calculator.calculateGeodeticCurve(Ellipsoid.Sphere, thisCoords, lastCoords);
        double azimuthToLast = curveToLast.getAzimuth();
        double distanceToLast = curveToLast.getEllipsoidalDistance();

        System.out.println(azimuthToLast);
        System.out.println(distanceToLast);
    }
}
